<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Model\Admin;
use App\Model\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class IndexController extends Controller
{
    /**
     * 菜单页
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $user = Auth::guard('admin')->user();
        return view('admin.index.index', ['user' => $user]);
    }

    /**
     * 侧边栏菜单
     * @return array
     */
    public function getMenu()
    {
        $id = Auth::guard('admin')->id();
        if (!$id) return [];
        $res = (new Admin())->getMenu($id);
        return $res;
    }

    public function forbidden()
    {
        return view('admin.403');
    }

    /**
     * 首页
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function main()
    {
        $userAmount = User::count();
        $version = DB::select('SELECT VERSION() AS ver');
        $systemInfo = [
            'url'             => $_SERVER['HTTP_HOST'],
            'document_root'   => $_SERVER['DOCUMENT_ROOT'],
            'server_os'       => PHP_OS,
            'server_port'     => $_SERVER['SERVER_PORT'],
            'server_ip'       => $_SERVER['SERVER_ADDR'],
            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
            'php_version'     => PHP_VERSION,
            'mysql_version'   => $version[0]->ver,
            'max_upload_size' => ini_get('upload_max_filesize')
        ];
        return view('admin.index.main', ['user_amount' => $userAmount, 'system_info' => $systemInfo]);
    }


}
